<?php
	// config and whatnot
    $config = dirname(__FILE__) . '/../config.php';
    require_once( "../Hybrid/Auth.php" );

	try{
		$hybridauth = new Hybrid_Auth( $config );
 
		$provider = $_GET["provider"];       // selected provider name 

		// call back the requested provider adapter instance 
		$adapter = $hybridauth->getAdapter( $provider );

		// logout the user from $provider
		$adapter->logout(); 

		// return to login page
		//$hybridauth->redirect( "login.php" );
		
		$_SESSION["fb_user_id"] = "";
		$_SESSION['fb_email'] = "";

		// 4.4 - redirect to user/profile
		//$this->redirect( "users/profile" );
		//header( "Location:http://www.maxcash.com.au/apply-now.php" ); social_logout
		die('<script>
			alert("your have successfully logged out");
			window.close();
			window.opener.document.getElementById("social_logout").setAttribute("style", "display:none;");
			window.opener.document.getElementById("fbconnect").removeAttribute("data");
			window.opener.document.getElementById("fbconnect").setAttribute("style", "cursor:pointer; display:block;");
			</script>
			');
		
    }
	catch( Exception $e ){
		// Display the recived error, 
		// to know more please refer to Exceptions handling section on the userguide
		switch( $e->getCode() ){ 
			case 0 : echo "Unspecified error."; break;
			case 1 : echo "Hybriauth configuration error."; break;
			case 2 : echo "Provider not properly configured."; break;
			case 3 : echo "Unknown or disabled provider."; break;
			case 4 : echo "Missing provider application credentials."; break; 
		} 

		echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();

		echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>"; 
	}
